<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>管理员页面</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<div class="layui-row layui-col-space15">
    <form class="layui-form">
        <blockquote class="layui-elem-quote">
            <div class="layui-inline">
                <a class="layui-btn layui-btn-normal addDoctor_btn">新增医生</a>
            </div>
        </blockquote>
    </form>
    <table id="doctors" lay-filter="doctors"></table>
</div>
<div class="layui-row layui-col-space15">
    <form class="layui-form">
        <blockquote class="layui-elem-quote">
            <div class="layui-inline">
                <a class="layui-btn layui-btn-normal addPatient_btn">新增患者</a>
            </div>
        </blockquote>
    </form>
    <table id="patients" lay-filter="patients"></table>
</div>
<script type="text/html" id="DoctorToolBar">
    <a class="layui-btn layui-btn-xs layui-bg-red" lay-event="delete">删除</a>
    <a class="layui-btn layui-btn-xs layui-bg-blue" lay-event="update">修改</a>
</script>
<script type="text/html" id="PatientToolBar">
    <a class="layui-btn layui-btn-xs layui-bg-red" lay-event="delete">删除</a>
    <a class="layui-btn layui-btn-xs layui-bg-blue" lay-event="update">修改</a>
</script>
</body>
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['table','form','jquery','laypage'],function () {
        var form = layui.form,
            table = layui.table,
            page = layui.laypage,
            $ = layui.jquery;

        //医生信息数据
        var doctors = table.render({
            elem: "#doctors",
            url: '/admin/listDoctor',
            limit: 5,
            limits: [5, 10, 15, 20, 25],
            page: true,
            loading:true,
            response: {
                statusName: 'code'
                , statusCode: 200
                , msgName: 'msg'
                , countName: 'count'
                , dataName: 'data'
            },
            id: 'doctors',
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},
                {field: 'id', title: 'ID', width: 60, align: "center"},
                {field: 'docName', title: '医生姓名', width:200, align: 'center'},
                {field:'docSex', title:'性别',width:80, align: 'center'},
                {field:'docTel', title:'联系方式',width:350, align: 'center'},
                {field:'docDate',title:'出生年月', align: 'center'},
                {field:'docTitle',title:'职称',width:200, align: 'center'},
                {title:'操作',templet:'#DoctorToolBar',fixed: "right",width:120,align:'center'}
            ]]
        });


        //患者信息数据
        var patients = table.render({
            elem: "#patients",
            url: '/admin/listPatient',
            limit: 5,
            limits: [5, 10, 15, 20, 25],
            page: true,
            loading:true,
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            response: {
                statusName: 'code'
                , statusCode: 200
                , msgName: 'msg'
                , countName: 'count'
                , dataName: 'data'
            },
            id: 'patients',
            cols: [[
                {type: "checkbox", fixed: "left", width: 50, align: 'center'},
                {field: 'id', title: 'ID', width: 60, align: "center"},
                {field: 'patName', title: '患者姓名',width:150, align: 'center'},
                {field:'patSex', title:'患者性别',width:100, align: 'center'},
                {field:'patTel', title:'患者联系方式',width:200, align: 'center'},
                {field:'patDate', title:'出生年月',width:200, align: 'center'},
                {field:'patAddress', title:'患者地址', align: 'center'},
                {field:'patId', title:'身份证号码',width:250, align: 'center'},
                {title: '操作', width: 120, templet: '#PatientToolBar', fixed: "right", align: "center"}
            ]]
        });



        /**
         * 弹出添加窗口 添加医生
         */
        $('.addDoctor_btn').click(function () {
            var index = layer.open({
                title:"添加医生",
                type:2,
                content:'./add_doctor.html',
                success: function (layero, index) {//参数绑定
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }

            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域
            $(window).on("resize",function(){
                layui.layer.full(index);
            })
        });




        /**
         * 弹出添加窗口  添加患者
         */
        $('.addPatient_btn').click(function () {
            var index = layer.open({
                title:"添加患者",
                type:2,
                content:'./add_patient.html',
                success: function (layero, index) {//参数绑定
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }

            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域
            $(window).on("resize",function(){
                layui.layer.full(index);
            })
        });



        /**
         * 医生删除
         */
        table.on('tool(doctors)',function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            console.log(data.id);
            if (layEvent === 'delete'){//监听修改
                layer.confirm('确定要删除该医生用户？', {icon: 3, title: '提示信息'}, function (index) {
                    $.ajax({
                        url: '/admin/deleteDoctor?id=' + data.id,
                        type: 'post',
                        success: function (res) {
                            if (res.code === 200) {
                                table.reload("doctors")
                                layer.msg("删除成功!");
                            } else {
                                layer.msg("删除失败!");
                            }
                        }
                    });
                });
            }else if (layEvent === 'update') {
                var index = layui.layer.open({
                    title : "修改医生",
                    type : 2,
                    content : "./updateDoctor.html",
                    success : function(layero, index){
                        var body = layui.layer.getChildFrame('body', index)
                        console.log("测试："+obj.data.docSex)
                        console.log(obj)
                        if(obj != null){
                            body.find(".id").val(obj.data.id);
                            body.find(".docName").val(obj.data.docName);
                            body.find(".radio[name=docSex]").val(obj.data.docSex);
                            body.find(".docTel").val(obj.data.docTel);
                            body.find(".docDate").val(obj.data.docDate);
                            body.find(".docTitle").val(obj.data.docTitle);
                            body.find(".docPassword").val(obj.data.docPassword);
                            form.render();
                        }
                        setTimeout(function(){
                            layui.layer.tips('点击此处返回医生列表', '.layui-layer-setwin .layui-layer-close', {
                                tips: 3
                            });
                        },1000)
                    }
                })
                layui.layer.full(index);
                //改变窗口大小时，重置弹窗的宽高，防止超出可视区域
                $(window).on("resize",function(){
                    layui.layer.full(index);
                })
            }
        });



        /**
         * 病人删除
         */
        table.on('tool(patients)',function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            console.log(data.id);
            if (layEvent === 'delete'){//监听修改
                layer.confirm('确定要删除该病人用户？', {icon: 3, title: '提示信息'}, function (index) {
                    $.ajax({
                        url: '/admin/deletePatient?id=' + data.id,
                        type: 'post',
                        success: function (res) {
                            if (res.code === 200) {
                                table.reload("patients")
                                layer.msg("删除成功!");
                            } else {
                                layer.msg("删除失败!");
                            }
                        }
                    });
                });
            }else if (layEvent === 'update') {
                var index = layui.layer.open({
                    title : "修改病人",
                    type : 2,
                    content : "./updatePatient.html",
                    success : function(layero, index){
                        var body = layui.layer.getChildFrame('body', index);
                        if(obj != null){
                            console.log(obj)
                            body.find(".id").val(obj.data.id);
                            body.find(".patName").val(obj.data.patName);
                            body.find(".patSex").val(obj.data.patSex);
                            body.find(".patTel").val(obj.data.patTel);
                            body.find(".patDate").val(obj.data.patDate);
                            body.find(".patAddress").val(obj.data.patAddress);
                            body.find(".patId").val(obj.data.patId);
                            body.find(".patPassword").val(obj.data.patPassword);
                            form.render();
                        }
                        setTimeout(function(){
                            layui.layer.tips('点击此处返回医生列表', '.layui-layer-setwin .layui-layer-close', {
                                tips: 3
                            });
                        },1000)
                    }
                })
                layui.layer.full(index);
                //改变窗口大小时，重置弹窗的宽高，防止超出可视区域
                $(window).on("resize",function(){
                    layui.layer.full(index);
                })
            }
        });



    });

</script>
</html>